<?php
	require_once("../conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<!--<script src="../include_js/prototype.js" type="text/javascript"></script>-->
<script src="../include_js/jquery.js" type="text/javascript"></script>
<!--<script src="include_js/select_dependientes.js" type="text/javascript"></script>-->
<style>
.filaPar
{
	background:#81D371; 
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
.filaImpar
{
	background:#AEF1A1;
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
a:link {color:#0033FF;} /* Link no visitado*/
a:visited {text-decoration:none; color:#999900} /*Link visitado*/
a:hover {color:#990000;} /*Mouse sobre el link*/
</style>
<script>
function CargaDetalle(valor)
{
	numero = document.getElementById("tablaFactura").rows[valor].cells[0].innerText;
	//alert("numero "+numero);
	window.open("Contabilidad/VentanaResumen.php?var="+numero,"VentanaResumen","width=741,height=400,scrollbars=yes");
}
function Formulario(valor)
{
	
	numero = document.getElementById("tablaFactura").rows[valor].cells[0].innerText;
	fecha = document.getElementById("tablaFactura").rows[valor].cells[2].innerText;
	//Codarea = document.getElementById("tablaFactura").rows[valor].cells[2].innerText;
	//alert(Codarea);
	window.open("Contabilidad/Ventana_Resumen_Factura.php?num="+numero+"&fecha="+fecha,"VentanaFacturaPSMB","width=810,height=550,scrollbars=yes");
}

function Direccionar()
{
	//alert('dir');
		$.ajax({
				type: 'POST',
				url: 'carga_busqueda_factura.php',
				data: $('#form_lista_busqueda').serialize(),
				success: function(data) {
					$('#listadoBusqueda').html(data);
				}
			})
}

function Eliminar(valor)
{
	id = document.getElementById("tablaFactura").rows[valor].cells[0].innerText;
	//alert(id);
		$.ajax({
					type: 'POST',
					url: 'Contabilidad/Eliminar_Factura.php',
					data: {id:id},
					success: function(data) {
						$('#eliminar').html(data);
						Direccionar();
					}
				})
}
</script>
</head>

<body>
<form name="form_lista_busqueda" id="form_lista_busqueda" method="post">
<?php
	extract($_POST); 
	$cont = 0;
	if (is_numeric($txtFactura)== true)
	{
		//echo "<br>";
		//echo "SI numero el formulario";
	}
	else
	{
	//echo "<br>";
	//echo "NO numero el formulario";
	//echo "<br>";
	}
	
	if (($txtFactura=="Numero Factura")or($txtFactura=="")) {
		$txtFactura="null";
		$cont++;
	}
	else
	{$txtFactura="'".$txtFactura."'";}
	
	if ($cmb_Area==0) {
		$cmb_Area="null";
		$cont++;
	}
	
	if ($cmb_Cliente==0) {
		$cmb_Cliente="null";
		$cont++;
	}
	
	if ($txtFIni==""){
		$txtFIni="null";
		$cont++;
	}
	else
	{
		$FechaIni = explode("-", $txtFIni);
		$txtFIni = "$FechaIni[2]-$FechaIni[1]-$FechaIni[0]";
	}
	
	if ($txtFFin==""){
		$txtFFin="null";
		$cont++;
	}
	else
	{
		$FechaFin = explode("-", $txtFFin);
		$txtFFin = "$FechaFin[2]-$FechaFin[1]-$FechaFin[0]";
	}

	if($cont != 5)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql="select distinct
			factura.FacCod as cod,
			AENombre,
			factura.AECod as aeCod,
			date_format(FacFecha,'%d/%m/%Y') as fecha,
			FacNeto
			
			from factura 
			inner join formulariofactura on
			formulariofactura.FacCod = factura.FacCod
			inner join areaextraccion on
			areaextraccion.AECod=factura.AECod
			
			where 
			(($txtFactura is NULL) or (factura.FacCod = $txtFactura)) and
			((".$cmb_Area." is NULL) or (factura.AECod = '".$cmb_Area."')) and
			((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(FacFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')
			order by factura.FacCod asc";		
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$fila = mysql_num_rows($res);
		//echo $fila;
		if($fila >0)
		{?>
		<table width="100%" border="0" class="uno" cellpadding="0" cellspacing="0" id="tablaFactura">
		<thead>
  		<tr>
    		<th width="13%">N&deg; Factura</th>
    		<th width="33%">Area</th>
    		<th width="12%" title="Fecha de Ingreso de la Factura">Fecha</th>
    		<th width="15%">neto ($)</th>
  		    <th width="11%">&nbsp;</th>
  		    <th width="2%">&nbsp;</th>
  		</tr>
 		</thead>
		<?php
		$aux=1;
		$cont=1;
		while($reg = mysql_fetch_array($res))
		{
			if(($cont % 2)==0)
			{
				echo "<tr class=\"filaPar\">";
				echo "<td width=\"13%\" class=\"filaPar\" id=\"".$aux."\"><a href=javascript:Formulario($aux);>".$reg['cod']."</a></td>";
				echo "<td width=\"31%\" class=\"filaPar\" id=\"".$aux."\">".$reg['AENombre']." "."(".$reg['aeCod'].")"."</td>";
				echo "<td width=\"12%\" class=\"filaPar\" id=\"".$aux."\">".$reg['fecha']."</td>";
				echo "<td width=\"15%\" class=\"filaPar\" id=\"".$aux."\">$".number_format ($reg['FacNeto'],0,',','.')."</td>";
				echo "<td width=\"11%\" class=\"filaPar\" id=\"".$aux."\"><a href=javascript:CargaDetalle($aux);>Ver Detalle</a></td>";
				echo "<td width=\"2%\" class=\"filaPar\" id=\"".$aux."\"><img src='imagen/delete_icon.gif' width='16' height='16' alt='Eliminar Factura' style='cursor:pointer;' onclick='Eliminar($aux);'/></td>";
				echo "</tr>";
			}
			else
			{
				echo "<tr class=\"filaImpar\">";
				echo "<td width=\"13%\" class=\"filaImpar\" id=\"".$aux."\"><a href=javascript:Formulario($aux);>".$reg['cod']."</a></td>";
				echo "<td width=\"31%\" class=\"filaImpar\" id=\"".$aux."\">".$reg['AENombre']." "."(".$reg['aeCod'].")"."</td>";
				echo "<td width=\"12%\" class=\"filaImpar\" id=\"".$aux."\">".$reg['fecha']."</td>";
				echo "<td width=\"15%\" class=\"filaImpar\" id=\"".$aux."\">$".number_format ($reg['FacNeto'],0,',','.')."</td>";
				echo "<td width=\"11%\" class=\"filaImpar\" id=\"".$aux."\"><a href=javascript:CargaDetalle($aux);>Ver Detalle</a></td>";
				echo "<td width=\"2%\" class=\"filaImpar\" id=\"".$aux."\"><img src='imagen/delete_icon.gif' width='16' height='16' alt='Eliminar Factura' style='cursor:pointer;' onclick='Eliminar($aux);'/></td>";
				echo "</tr>";
			}
			$aux++;
			$cont++;
		}
		$con->cerrarBD();
		?>
		</table>
		<?php }
		
		else
		{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
	}
	else
	{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
?>
<div id="eliminar"></div>
</form>
</body>
</html>
